import http from './http';

// 系统配置相关API
export const systemConfigApi = {
  // 获取所有系统配置
  getAll: () => http.get('/api/system-config'),
  // 根据ID获取系统配置
  getById: (id) => http.get(`/api/system-config/${id}`),
  // 添加系统配置
  add: (data) => http.post('/api/system-config', data),
  // 更新系统配置
  update: (id, data) => http.put(`/api/system-config/${id}`, data),
  // 删除系统配置
  delete: (id) => http.delete(`/api/system-config/${id}`)
};

// 数据库配置相关API
export const databaseConfigApi = {
  // 获取所有数据库配置
  getAll: () => http.get('/api/database-config'),
  // 根据ID获取数据库配置
  getById: (id) => http.get(`/api/database-config/${id}`),
  // 检查配置名称是否存在
  checkName: (name) => http.get(`/api/database-config/name/${name}`),
  // 添加数据库配置
  add: (data) => http.post('/api/database-config', data),
  // 更新数据库配置
  update: (id, data) => http.put(`/api/database-config/${id}`, data),
  // 删除数据库配置
  delete: (id) => http.delete(`/api/database-config/${id}`)
};

// 菜单相关API
export const menuApi = {
  // 获取所有菜单
  getAll: () => http.get('/api/menu'),
  // 根据角色获取菜单
  getByRole: (roleId) => http.get(`/api/menu/role/${roleId}`),
  // 根据ID获取菜单
  getById: (id) => http.get(`/api/menu/${id}`),
  // 更新菜单
  update: (id, data) => http.put(`/api/menu/${id}`, data),
  // 删除菜单
  delete: (id) => http.delete(`/api/menu/${id}`)
};

// 数据库管理相关API
export const dbManagementApi = {
  // 获取数据库列表
  getDatabases: (dbConfigId, params = {}) => http.get(`/api/db-management/databases/${dbConfigId}`, params),
  // 同步数据库信息
  syncDatabases: (dbConfigId) => http.post(`/api/db-management/sync-databases/${dbConfigId}`),
  // 同步表结构
  syncSchema: (data) => http.post('/api/db-management/sync-schema', data)
};

// 数据库模式相关API
export const schemaApi = {
  // 获取表列表
  getTables: (dbConfigId) => http.get(`/api/schema/tables/${dbConfigId}`),
  // 获取表字段信息
  getTableColumns: (dbConfigId, tableName) => http.get(`/api/schema/columns/${dbConfigId}/${tableName}`),
  // 获取表结构信息
  getTableSchema: (dbConfigId, tableName) => http.get(`/api/schema/table/${dbConfigId}/${tableName}`),
  // 保存表结构
  saveTable: (data) => http.post('/api/schema/save-table', data),
  // 批量保存表结构
  batchSaveTables: (data) => http.post('/api/schema/batch-save-tables', data)
};

// 设备相关API
export const deviceApi = {
  // 获取所有设备
  getAll: () => http.get('/api/devices'),
  // 根据ID获取设备
  getById: (id) => http.get(`/api/devices/${id}`),
  // 添加设备
  add: (data) => http.post('/api/devices', data),
  // 更新设备
  update: (id, data) => http.put(`/api/devices/${id}`, data),
  // 删除设备
  delete: (id) => http.delete(`/api/devices/${id}`)
};

// 区域相关API
export const areaApi = {
  // 获取所有区域
  getAll: () => http.get('/api/areas'),
  // 根据ID获取区域
  getById: (id) => http.get(`/api/areas/${id}`),
  // 添加区域
  add: (data) => http.post('/api/areas', data),
  // 更新区域
  update: (id, data) => http.put(`/api/areas/${id}`, data),
  // 删除区域
  delete: (id) => http.delete(`/api/areas/${id}`)
};

// 用户相关API
export const userApi = {
  // 登录
  login: (data) => http.post('/api/login', data),
  // 登出
  logout: () => http.post('/api/logout'),
  // 获取当前用户信息
  getCurrent: () => http.get('/api/user/current'),
  // 获取用户列表
  getAll: (params = {}) => http.get('/api/users', params),
  // 添加用户
  add: (data) => http.post('/api/users', data),
  // 更新用户
  update: (id, data) => http.put(`/api/users/${id}`, data),
  // 删除用户
  delete: (id) => http.delete(`/api/users/${id}`)
};

// 角色相关API
export const roleApi = {
  // 获取所有角色
  getAll: () => http.get('/api/roles'),
  // 根据ID获取角色
  getById: (id) => http.get(`/api/roles/${id}`),
  // 添加角色
  add: (data) => http.post('/api/roles', data),
  // 更新角色
  update: (id, data) => http.put(`/api/roles/${id}`, data),
  // 删除角色
  delete: (id) => http.delete(`/api/roles/${id}`),
  // 获取角色菜单权限
  getRoleMenus: (roleId) => http.get(`/api/roles/${roleId}/menus`),
  // 更新角色菜单权限
  updateRoleMenus: (roleId, data) => http.put(`/api/roles/${roleId}/menus`, data)
};

// 日志相关API
export const logApi = {
  // 获取操作日志
  getOperationLogs: (params = {}) => http.get('/api/logs/operation', params),
  // 获取系统日志
  getSystemLogs: (params = {}) => http.get('/api/logs/system', params)
};

// 同步策略相关API
export const syncStrategyApi = {
  // 获取所有同步策略
  getAll: (params = {}) => http.get('/api/sync-strategy', params),
  // 根据ID获取同步策略
  getById: (id) => http.get(`/api/sync-strategy/${id}`),
  // 检查策略名称是否存在
  checkName: (name) => http.get(`/api/sync-strategy/name/${name}`),
  // 添加同步策略
  add: (data) => http.post('/api/sync-strategy', data),
  // 更新同步策略
  update: (id, data) => http.put(`/api/sync-strategy/${id}`, data),
  // 删除同步策略
  delete: (id) => http.delete(`/api/sync-strategy/${id}`)
};

// 服务类型相关API
export const serviceTypeApi = {
  // 获取服务类型列表（分页）
  getAll: (params = {}) => http.get('/api/service-types/page', params),
  // 获取所有服务类型（不分页）
  getAllList: () => http.get('/api/service-types'),
  // 根据ID获取服务类型
  getById: (id) => http.get(`/api/service-types/${id}`),
  // 添加服务类型
  add: (data) => http.post('/api/service-types', data),
  // 更新服务类型
  update: (id, data) => http.put(`/api/service-types/${id}`, data),
  // 删除服务类型
  delete: (id) => http.delete(`/api/service-types/${id}`)
};

// 数据同步管理相关API
export const syncTaskApi = {
  // 获取服务列表
  getAll: (params = {}) => http.get('/api/server-services', params),
  // 获取服务列表（分页）
  getPage: (params = {}) => http.get('/api/server-services/page', params),
  // 根据ID获取服务
  getById: (id) => http.get(`/api/server-services/${id}`),
  // 添加服务
  add: (data) => http.post('/api/server-services', data),
  // 更新服务
  update: (id, data) => http.put(`/api/server-services/${id}`, data),
  // 删除服务
  delete: (id) => http.delete(`/api/server-services/${id}`)
};

// 导出所有API模块
export default {
  systemConfigApi: systemConfigApi,
  databaseConfigApi: databaseConfigApi,
  menuApi: menuApi,
  dbManagementApi: dbManagementApi,
  schemaApi: schemaApi,
  deviceApi: deviceApi,
  areaApi: areaApi,
  userApi: userApi,
  roleApi: roleApi,
  logApi: logApi,
  syncStrategyApi: syncStrategyApi,
  serviceTypeApi: serviceTypeApi,
  syncTaskApi: syncTaskApi
};